﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace CorpStore.Models
{
    /// <summary>
    /// This class encapsulates any data which needs to be passed from one page to another.  
    /// This class is typically serialized when being passed as a navigation parameter since
    /// this results in more consistent behavior.
    /// </summary>
    class NavData
    {
        public PackageInfo CurrentApp;
        public PackageInfoGroup CurrentGroup;
        public string FamilyName;
        public string ActiveGroupName; // not used currently but could be used in future from secondary tiles to navigate directly to specific groups (knh 3/24/14)

        public string Serialize()
        {
            return JsonConvert.SerializeObject(this);
        }

        public static NavData Deserialize(string serializedData, out string errStr)
        {
            NavData data = null;

            errStr = "";
            try
            {
                data = JsonConvert.DeserializeObject<NavData>(serializedData);
            }
            catch (Exception ex)
            {
                errStr = string.Format("Unhandled exception while trying to deserialize navdata: {0}", ex.Message);
            }

            return data;
        }
    }
}
